package fr.toto.triseries;

import java.nio.file.Path;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Pattern;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.LocalizedMessage;

import fr.toto.constantes.Constantes;
import fr.toto.files.ActionFile;
import fr.toto.menuitem.OpenDirMenuItem;
import fr.toto.subtitles.DldSoutitre;
import fr.toto.subtitles.Soutitre;

/**
 * @author tshepo
 * 
 */
public class DetailFile implements ActionFile, Constantes {

	private static ExecutorService es;
	private static final Logger logger = LogManager
			.getLogger(OpenDirMenuItem.class);

	public DetailFile() {
		es = Executors.newSingleThreadExecutor();
	}

	@Override
	public void executer(Path file) {
		if (Pattern.compile(Regex.VIDEOFILE).matcher(file.toString()).find()) {
			logger.info(new LocalizedMessage(DEBUGMSG,
					"fr.toto.triseries.DetailFile.videofile", file));
			es.execute(new Video(file));
		}
		if (Pattern.compile(Regex.SUBTITLEFILE).matcher(file.toString()).find()){
			logger.info(new LocalizedMessage(DEBUGMSG,
					"fr.toto.triseries.DetailFile.subtitlefile", file));
			es.execute(new DldSoutitre(file));
		}
	}

	public void executer(Soutitre sub) {
		es.execute(sub);
	}

}
